from globals import *
import socket

def get_from_auth_server (MESSAGE) :

    s=socket.socket(socket.AF_INET, socket.SOCK_STREAM);
    s.connect((AUTH_SERVER_IP, AUTH_SERVER_PORT))
    s.send(MESSAGE)
    data = s.recv(BUFFER_SIZE)
    if data == 'NACK' :
        return None

    return data

def test_cookie(user, cookie):
    return get_from_auth_server("test_cookie;" + user + ";" + cookie)

def get_user_metadata (user) :
    return get_from_auth_server ("get_user_metadata;" + user)

def unlink_from_auth_server (source, dest) :
    return get_from_auth_server ("remove_edge;" + source + ";" + dest)

def validate_from_auth_server (toUserName) :
    return get_from_auth_server ("validate_userlist;" + toUserName)

def get_config_from_auth_server (thisName) :
    return get_from_auth_server ("get_config;" + thisName)
